#pragma once
#include <cstdint>
#include <functional>
#include <memory>
#include <string>

#include "result.hpp"

class BroadcastAcceptor
{
public:
    using Callback = std::function<void(const std::vector<uint8_t>& data, const std::string& from_ip,
                                        uint16_t from_port)>;

    explicit BroadcastAcceptor(const Callback& callback);
    ~BroadcastAcceptor();

    cpp::Result<> init(uint16_t listen_port, const std::string& interface_address = "0.0.0.0");

    void run();

    cpp::Result<> release();

private:
    class Impl;
    std::unique_ptr<Impl> pimpl;
};
